<?php

/**
 * @author Archer
 * @note 路由处理方法
 * @mail 188802862@qq.com
 */

namespace console\core;

use \console\core\manager\InstanceManager;

class Router extends InstanceManager
{
    //添加一个任意模式路由
    static function add($pattern = '' , $conf = [])
    {
        self::Router()->add($pattern,$conf);
    }

    //添加一个GET请求路由
    static function addGet($pattern = '' , $conf = [])
    {
        self::Router()->addGet($pattern , $conf);
    }

    //添加一个Post请求路由
    static function addPost($pattern = '' , $conf = [])
    {
        self::Router()->addPost($pattern , $conf);
    }

    //添加一个Put请求
    static function addPut($pattern = '' , $conf = [])
    {
        self::Router()->addPut($pattern , $conf);
    }

    //添加一个Delete请求
    static function addDelete($pattern = '' , $conf = [])
    {
        self::Router()->addDelete($pattern , $conf);
    }

    //批量添加路由请求
    static function batchAdd($router = [])
    {
        if(!empty($router))
            array_walk($router,create_function('$v,$k',__NAMESPACE__.'\Router::add($k,$v);'));
    }

    //批量添加路由Get请求
    static function batchAddGet($router = [])
    {
        if(!empty($router))
            array_walk($router,create_function('$v,$k',__NAMESPACE__.'\Router::addGet($k,$v);'));
    }

    //批量添加路由Post请求
    static function batchAddPost($router = [])
    {
        if(!empty($router))
            array_walk($router,create_function('$v,$k',__NAMESPACE__.'\Router::addPost($k,$v);'));
    }

    //批量添加Put请求
    static function batchAddPut($router = [])
    {
        if(!empty($router))
            array_walk($router,create_function('$v,$k',__NAMESPACE__.'\Router::addPut($k,$v);'));
    }

    //批量添加Delete请求
    static function batchAddDelete($router = [])
    {
        if(!empty($router))
            array_walk($router,create_function('$v,$k',__NAMESPACE__.'\Router::addDelete($k,$v);'));
    }

    //路由解析
    static function handle($uri = '')
    {
        return self::Router()->handle($uri);
    }

    //路由验证
    static function wasMatched()
    {
        return self::Router()->wasMatched();
    }

    //获取控制器名称
    static function getControllerName()
    {
        return self::Router()->getControllerName();
    }

    //获取操作名称
    static function getActionName()
    {
        return self::Router()->getActionName();
    }

    //获取命名空间
    static function getNamespaceName()
    {
        return self::Router()->getNamespaceName();
    }
}